
package edu.wpi.first.wpilibj.templates;
//this comment from imac and toshiba
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.templates.commands.CollectBalls;
import edu.wpi.first.wpilibj.templates.commands.CycleBalls;
import edu.wpi.first.wpilibj.templates.commands.DriveStraight;
import edu.wpi.first.wpilibj.templates.commands.SetShooterSpeed;
import edu.wpi.first.wpilibj.templates.commands.SlashDown;
import edu.wpi.first.wpilibj.templates.commands.SlashUp;


/**
 * This class is the glue that binds the controls on the physical operator
 * interface to the commands and command groups that allow control of the robot.
 */
public class OI {
    private static OI instance = null;
    private Joystick drivestick;
    private JoystickButton drivestraight;
    private Joystick buttonboard;
    private JoystickButton shooter_enable_button;
    private JoystickButton slash_up_button;
    private JoystickButton slash_down_button;  
    private JoystickButton collect_balls;
    private JoystickButton cycle_balls;
    private JoystickButton auto_1;
    private JoystickButton auto_2;
    private JoystickButton auto_3;
    private JoystickButton auto_4;
    public boolean[] auto_array;
    
    
    public OI() {
        drivestick = new Joystick(RobotMap.DRIVE_JOYSTICK_PORT);
        auto_1 = new JoystickButton(drivestick, 1);
        auto_2 = new JoystickButton(drivestick, 2);
        auto_3 = new JoystickButton(drivestick, 3);
        auto_4 = new JoystickButton(drivestick, 4);
        drivestraight = new JoystickButton(drivestick, 3);
        drivestraight.whenPressed(new DriveStraight(2));
        buttonboard = new Joystick(2);
        shooter_enable_button = new JoystickButton(buttonboard, 3);
        shooter_enable_button.whileHeld(new SetShooterSpeed(DriverStation.getInstance().getAnalogIn(1)));
        slash_up_button = new JoystickButton(drivestick, 7);
        slash_down_button = new JoystickButton(drivestick, 8);
        slash_up_button.whileHeld(new SlashUp());
        slash_down_button.whileHeld(new SlashDown());
        collect_balls = new JoystickButton(drivestick, RobotMap.BALL_COLLECT_JOYSTICK_BUTTON);
        cycle_balls = new JoystickButton(drivestick, RobotMap.BALL_CYCLE_JOYSTICK_BUTTON);
        collect_balls.whileHeld(new CollectBalls());
        cycle_balls.whenPressed(new CycleBalls());
        
        //When I hold shooter_enable_button, it will keep making new setshooterspeed
        //commands.  These commands will set the shootspeed value to the pot
        //the whileheld method is used so that commands keep being created. The set speed command
        //only updates the setpoint in the init area, so a new command needs to be started. 
        //If I wanted to be efficient, I could make a second command which puts the setsetpoint 
        //in the execute method.  I could also create a method in IO whcih gets the value of the pot and a 
        //command class which sends this value to the setsetpoint method in the PID subsystem.
        
         
        
        
        
    }
    
    public static OI getInstance() {
        if (instance==null) {
            instance = new OI();
        }
        return instance;
    }
    
    public Joystick getDriveStick() { //method for getting joystick stuff
        return drivestick;
    }
    public boolean[] getAutoArray(){
        auto_array[0]=auto_1.get();
        auto_array[1]=auto_2.get();
        auto_array[2]=auto_3.get();
        auto_array[3]=auto_4.get();
        return auto_array;
        
        
    }
            
   
    public double getShooterPot(){
        return DriverStation.getInstance().getAnalogIn(1);
    }
    //// CREATING BUTTONS
    // One type of button is a joystick button which is any button on a joystick.
    // You create one by telling it which joystick it's on and which button
    // number it is.
    // Joystick stick = new Joystick(port);
    // Button button = new JoystickButton(stick, buttonNumber);
    
    // Another type of button you can create is a DigitalIOButton, which is
    // a button or switch hooked up to the cypress module. These are useful if
    // you want to build a customized operator interface.
    // Button button = new DigitalIOButton(1);
    
    // There are a few additional built in buttons you can use. Additionally,
    // by subclassing Button you can create custom triggers and bind those to
    // commands the same as any other Button.
    
    //// TRIGGERING COMMANDS WITH BUTTONS
    // Once you have a button, it's trivial to bind it to a button in one of
    // three ways:
    
    // Start the command when the button is pressed and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenPressed(new ExampleCommand());
    
    // Run the command while the button is being held down and interrupt it once
    // the button is released.
    // button.whileHeld(new ExampleCommand());
    
    // Start the command when the button is released  and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenReleased(new ExampleCommand());
}

